import { MessageBox } from 'element-ui'

export default {
  messageBox: (title, message, type, callback = null, then = null) => {
    MessageBox.alert(message, title, {
      confirmButtonText: '确定',
      type: type,
      callback: (flag) => {
        if (callback !== null) {
          callback(flag)
        }
      }
    }).then(r => {
      if (then !== null) {
        then(r)
      }
    })
  },
  successBox: (title, message, callback = null, then = null) => {
    return this.messageBox(title, message, 'success', callback, then)
  },
  errorBox: (title, message, callback = null, then = null) => {
    return this.messageBox(title, message, 'error', callback, then)
  },
  warningBox: (title, message, callback = null, then = null) => {
    return this.messageBox(title, message, 'warning', callback, then)
  }
}
